<template>
  <div class="rating-select">
    <div class="rating-type">
      <span class="block positive" @click="select(2)" :class="{'active': selectType === 2}">{{desc.all}}<span class="count">{{ratings.length}}</span></span>
      <span class="block positive" @click="select(0)" :class="{'active': selectType === 0}">{{desc.positive}}<span class="count">{{positives.length}}</span></span>
      <span class="block negative" @click="select(1)" :class="{'active': selectType === 1}">{{desc.negative}}<span class="count">{{negatives.length}}</span></span>
    </div>
    <div class="switch" @click="toggleOnly" >
      <span class="icon-check_circle" :class="{'on': onlyContent}"></span>
      <span class="text">只看有内容的评价</span>
    </div>
  </div>
</template>
<script>
const ALL = 2
const POSITIVE = 0
const NEGATIVE = 1
export default {
  name: 'RatingSelect',
  props: {
    ratings: {
      type: Array,
      default () {
        return []
      }
    },
    selectType: {
      type: Number,
      default: ALL
    },
    onlyContent: {
      type: Boolean,
      default: true
    },
    desc: {
      type: Object,
      default () {
        return {
          all: '全部',
          positive: '满意',
          negative: '不满意'
        }
      }
    }
  },
  computed: {
    positives () {
      return this.ratings.filter((rating) => {
        return rating.rateType === POSITIVE
      })
    },
    negatives () {
      return this.ratings.filter((rating) => {
        return rating.rateType === NEGATIVE
      })
    }
  },
  methods: {
    select (type) {
      this.$emit('select', type)
    },
    toggleOnly () {
      this.$emit('toggleOnly')
    }
  }
}
</script>
<style scoped lang="stylus">
.rating-select
  .rating-type
    margin 0 .36rem
    padding .36rem 0
    font-size 0
    border-bottom .02rem solid rgba(7, 17, 27, 0.1)
    .block
      display inline-block
      font-size .24rem
      padding .16rem .24rem
      border-radius .04rem
      margin-right .16rem
      line-height .32rem
      .count
        font-size .16rem
        margin-left .08rem
    .positive
      background-color rgba(0, 160, 220, 0.2)
      &.active
        background-color rgb(0, 160, 220)
        color #fff
    .negative
      background-color rgba(77, 85, 93, 0.2)
      &.active
        background-color rgb(77, 85, 93)
        color #fff
  .switch
    padding .24rem .36rem
    font-size 0
    color rgb(147, 153, 159)
    border-bottom .03rem solid rgba(7, 17, 27, 0.1)
    .icon-check_circle
      font-size .48rem
      line-height .48rem
      margin-right .08rem
      vertical-align top
      &.on
        color #00c850
    .text
      font-size .24rem
      line-height .48rem
      vertical-align top
</style>
